/**
 * 智能体系统主入口
 * 提供智能体的配置、管理和调度功能
 */

// 导入核心模块
import { AgentScheduler } from './src/solo/AgentScheduler';
import { SoloModeApp } from './src/solo/index';
import { BaseAgent } from './src/core/BaseAgent';
import { DetectiveAssistant } from './src/agents/DetectiveAssistant';
import { ProfileAnalyzer } from './src/agents/ProfileAnalyzer';

// 导出所有公共API
export {
  // 核心类
  AgentScheduler,
  SoloModeApp,
  BaseAgent,
  
  // 智能体实现
  DetectiveAssistant,
  ProfileAnalyzer,
  
  // 便捷函数
  createSoloMode,
  getAvailableAgents,
  executeTask
};

/**
 * 创建并配置Solo模式
 * @param options 配置选项
 * @returns SoloModeApp实例
 */
export function createSoloMode(options?: {
  configPath?: string;
  maxConcurrentTasks?: number;
  defaultTimeout?: number;
  logLevel?: 'debug' | 'info' | 'warn' | 'error';
}): SoloModeApp {
  const app = new SoloModeApp();
  
  if (options) {
    app.configureSoloMode({
      maxConcurrentTasks: options.maxConcurrentTasks,
      defaultTimeout: options.defaultTimeout,
      logLevel: options.logLevel
    });
  }
  
  return app;
}

/**
 * 获取所有可用的智能体
 * @returns 智能体配置数组
 */
export function getAvailableAgents(configPath?: string): any[] {
  const scheduler = new AgentScheduler(configPath || './config/agents-config.json');
  return scheduler.getAvailableAgents();
}

/**
 * 执行单个任务
 * @param request 任务请求
 * @param configPath 配置文件路径
 * @returns 任务结果
 */
export async function executeTask(
  request: {
    taskType: string;
    agentId: string;
    input: Record<string, any>;
    priority?: 'high' | 'medium' | 'low';
  },
  configPath?: string
): Promise<any> {
  const scheduler = new AgentScheduler(configPath || './config/agents-config.json');
  
  const taskRequest = {
    taskId: `task_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
    ...request
  };
  
  const result = await scheduler.executeTask(taskRequest);
  
  if (result.success) {
    return result.result;
  } else {
    throw new Error(result.error);
  }
}

// 如果直接运行此文件，则启动Solo模式应用
if (require.main === module) {
  console.log('=== 智能体系统启动 ===');
  const app = createSoloMode();
  app.start();
}
